package com.learn.hibernatevalidator.chapter07.valueextractor.valueextractor;

import com.google.common.collect.Multimap;
import jakarta.validation.valueextraction.ExtractedValue;
import jakarta.validation.valueextraction.ValueExtractor;

import java.util.Collection;
import java.util.Map;

/**
 * @author: liyf
 * @create: 2025-01-18 23:09
 **/
public class MultimapValueValueExtractor implements ValueExtractor<Multimap<?, @ExtractedValue ?>> {

    @Override
    public void extractValues(Multimap<?, ?> originalValue, ValueReceiver receiver) {

        Collection<? extends Map.Entry<?, ?>> entries = originalValue.entries();
        for (Map.Entry<?, ?> entry : entries) {
            receiver.keyedValue("<multimap value>", entry.getKey(), entry.getValue());
        }

    }
}
